<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

error_reporting(0);

//--------------------------------------
if ( ! function_exists('temPermissao'))
{
	function temPermissao($permissao,$session_data)
	{
		if (!in_array($session_data["permissao"], $permissao)){ 
			redirect('inicio/sorry');
		}
	}
}
if ( ! function_exists('viewPermissao'))
{
	function viewPermissao($permissao,$session_data)
	{
		if (!in_array($session_data["permissao"], $permissao)){ 
			return false;
		}else{
			return true;
		}
	}
}
if ( ! function_exists('validaActiveDirectoryProcurador'))
{
	function validaActiveDirectoryProcurador($user, $password,$group){
	
		// Active Directory server
		$ldap_host = "tucano.arapongas.pr.gov.br";
		// Active Directory DN
		$ldap_dn = "OU=Usuarios,DC=arapongas,DC=pr,DC=gov,DC=br";
		// Domain, for purposes of constructing $user
		$ldap_usr_dom = "@arapongas.pr.gov.br";
		
		// Connect to AD
		$ldap = ldap_connect($ldap_host) or die('<div class="alert alert-danger" role="alert">Erro ao conectar no servidor</div>');
		
		if($ldap) {
			$ldapbind = ldap_bind($ldap,$user.$ldap_usr_dom,$password) or die('<div class="alert alert-danger" role="alert">Erro ao consultar servidor</div>');
			if($ldapbind) {
				$query = "(&(objectClass=user)(objectCategory=person)
				(
				|(memberof=CN=$group,OU=Grupos,DC=arapongas,DC=pr,DC=gov,DC=br)
				(memberof=CN=SEMAD - DTI,OU=Grupos,DC=arapongas,DC=pr,DC=gov,DC=br)
				)
				)";
				$attr = array("sAMAccountName");
				$results = ldap_search($ldap,$ldap_dn,$query,$attr) or die ('<div class="alert alert-danger" role="alert">Erro na busca: '.ldap_error($ldap).'</div>');
				$entries = ldap_get_entries($ldap, $results);
				array_shift($entries);
				$data = array();
				foreach($entries as $user1){
					$string = $user1['samaccountname'][0];
					$data[] = $string;
				}
				if(in_array($user, $data)){
					return true;
				}else{
					return false;
				}
			}else{
				return false;
			}
		}else{
			echo '<div class="alert alert-danger" role="alert">Nenhum servidor encontrado</div>';
		}
	
	
	}
}
if ( ! function_exists('brToUsa'))
{
	function brToUsa($data)
	{
		$data = explode("/", $data);
		$data = $data[2]."-".$data[1]."-".$data[0];
		return $data;
	}
}
//--------------------------------------
if ( ! function_exists('UsaToBr'))
{
	function usaToBr($data)
	{
		if($data != ''){
			$data = explode("-", $data);
			$data1 = $data[2]."/".$data[1]."/".$data[0];
			return $data1;
		}	
	}
}
//--------------------------------------
if ( ! function_exists('brToUsaHora'))
{
	function brToUsaHora($data)
	{
		$data = explode(" ", $data);
		$dia = explode("/", $data[0]);
		$data = $dia[2]."-".$dia[1]."-".$dia[0]." ".$data[1];
		return $data;
	}
}
//--------------------------------------
if ( ! function_exists('UsaToBrHora'))
{
	function usaToBrHora($data)
	{
		if($data != ''){
			$data = explode(" ", $data);
			$dia = explode("-", $data[0]);
			$hora = $data[1];
			$data1 = $dia[2]."/".$dia[1]."/".$dia[0]." ".$hora;
			return $data1;
		}
	}
}
//--------------------------------------
if ( ! function_exists('statusEvento'))
{
	function statusEvento($tipoevento)
	{
		if($tipoevento > 2 && $tipoevento <6){
			$status = "AE";
		}elseif($tipoevento > 5 && $tipoevento < 8){
			$status = "PE";
		}
		return $status;
	}
}

if ( ! function_exists('statusHistorico'))
{
	function statusHistorico($status)
	{
		switch($status){
			case 'E': $string = " SISTEMA ";break;
			case 'S': $string = " DE SAIDA ";break;
			case 'D': $string = " DESARQUIVADO ";break;
			case 'AS': $string = " PARA ASSISTENTE";break;
			case 'ASR': $string = " PARA ADVOGADO";break;
			case 'RM': $string = " AUTOMÁTICA (MANUAL)";break;
			case 'RS': $string = " PROCURADOR GERAL";break;
			default: $string = "";break;
		}
		
		return $string;
	}
}
if ( ! function_exists('gerarRelatorio'))
{
	 function gerarRelatorio($pdf){
			//$pdf = new Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
			// Add a page
			// set document information
			$pdf->SetCreator(PDF_CREATOR);
			$pdf->SetAuthor('PROJU');
			$pdf->SetTitle('');
			$pdf->SetSubject('PROJU');
			//$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

			// set default header data
			$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 006', PDF_HEADER_STRING);

			// set header and footer fonts
			$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
			$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

			// set default monospaced font
			$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

			// set margins
			$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
			$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
			$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

			// set auto page breaks
			$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
			
			// set image scale factor
			$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
			
			
	}
       
}
//--------------------------------------

/* End of file MY_funcoes_auxiliares.php */
/* Location: ./application/helpers/MY_funcoes_auxiliares.php */